package com.yc.weixin.util;

import java.util.Date;

/**
 * 数据字典类
 * @author Administrator
 *
 */
public class Constants {
	
	public static String access_token;			//access_token的值
	public static long access_tokenTime;			//access_token的有效时间
	
	
	/**
	 * 判断access_token是否已经失效
	 * @return
	 */
	public static String getaccess_tokenByTime(){
		String access_token="";
		if(Constants.access_token==null || "".equals(Constants.access_token)){
			access_token=HttpsRequest.getAccess_token("wx7e4e3566f6bbc5d5", "b1749ed2942981be57fee8b11fdb1e3b");
			Constants.access_token=access_token;
			Constants.access_tokenTime=new Date().getTime()/1000;
		}
		if(Constants.access_token!=null){
			long time=new Date().getTime()/1000-Constants.access_tokenTime;
			if(time>7200){
				access_token=HttpsRequest.getAccess_token("wx7e4e3566f6bbc5d5", "b1749ed2942981be57fee8b11fdb1e3b");
				Constants.access_token=access_token;
				Constants.access_tokenTime=new Date().getTime()/1000;
			}
		}
		access_token=Constants.access_token;
		return access_token;
	}
}
